
#include "net.h"



static int baidu_server_parse(const * json_data)
{
		
	if(!json_data){
		return 0;
	}


	log_i("json_data=%s\n",json_data);

	
	return 0;

}



static size_t baidu_server_callback(void *buffer, size_t size, size_t nmemb, void *usr_data)
{	

	if(buffer){
		baidu_server_parse(buffer);
	}
	

    return size*nmemb;
}


int net_baidu_server(void)
{	
	static CURL *keycurl = NULL;	 
	CURLcode res;	  	
	long	 retcode  = 0;
	CURLcode code ;


	if(keycurl == NULL){
		keycurl = curl_easy_init(); 	
	}
	if(keycurl == NULL){
		log_e("curl easy init error\n");
		return 0;
	}

	curl_easy_setopt(keycurl, CURLOPT_CUSTOMREQUEST, "GET");
	curl_easy_setopt(keycurl, CURLOPT_URL, "https://www.ku138.cc/b/94/47716.html");
	curl_easy_setopt(keycurl, CURLOPT_WRITEFUNCTION,  baidu_server_callback);			
	curl_easy_setopt(keycurl, CURLOPT_WRITEDATA, NULL);

	curl_easy_setopt(keycurl, CURLOPT_TIMEOUT, 15);
	curl_easy_setopt(keycurl, CURLOPT_MAXREDIRS, 1);
	curl_easy_setopt(keycurl, CURLOPT_CONNECTTIMEOUT, 25);

	curl_easy_setopt(keycurl, CURLOPT_SSL_VERIFYPEER, 0); 
	curl_easy_setopt(keycurl, CURLOPT_SSL_VERIFYHOST, 0);
	res = curl_easy_perform(keycurl);
	if(res != CURLE_OK)
	{
		log_e("Failed to get res = %x\n",res); 	
	}	
	else
	{
		code = curl_easy_getinfo(keycurl, CURLINFO_RESPONSE_CODE , &retcode);
		if((code == CURLE_OK) && retcode == 200)
		{
			res  = CURLE_OK;
		}
		else
		{
			res = -1;
			log_e("getinfo error\n");
		}
	}

	curl_easy_cleanup(keycurl); 
	keycurl = NULL;
	
	return 0;
}








